package com.inspur.edp.ai.flow.metadata.serializer;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.inspur.edp.ai.flow.metadata.AbsNode;
import com.inspur.edp.ai.flow.spi.NodeDeserializerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lizhaorui
 * @date 2025/8/19
 * @description
 */
public class NodesJsonDeserializer extends JsonDeserializer<List<AbsNode>> {

    @Override
    public List<AbsNode> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        JsonNode arrayNode = jsonParser.getCodec().readTree(jsonParser);
        if (arrayNode == null) {
            return null;
        }
        List<AbsNode> flowNodes = new ArrayList<>();
        for (JsonNode jsonNode : arrayNode) {
            AbsNode flowNode = NodeDeserializerFactory.deserialize(jsonNode);
            flowNodes.add(flowNode);
        }
        return flowNodes;
    }
}